@echo off

echo Install SiemensCollect-NCU4.7x to NCU on Windows
echo ------------------------------------------------------

set LOCAL_FILE=SiemensCollect-NCU4.7x.sh
set REMOTE_FILE=~/%LOCAL_FILE%

:LBL_BEGIN
echo.
set /p ADDRESS=NCU's address (host[:port]) : 
for /f "tokens=1,2delims=:" %%i in ("%ADDRESS%") do (
  set HOST=%%i
  set PORT=%%j
)
if "%HOST%" == "" (
  echo NCU's address cannot be empty
  goto LBL_BEGIN
)
if "%PORT%" == "" (
  set PORT=22
)

echo.
set /p USER=NCU's user : 
if "%USER%" == "" (
  set USER=manufact
)

echo.
echo Uploading %LOCAL_FILE% to NCU %HOST% ...
scp -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedKeyTypes=+ssh-rsa -oMacs=+hmac-sha1 -O -P %PORT% %LOCAL_FILE% %USER%@%HOST%:%REMOTE_FILE%
if NOT %errorlevel% == 0 (
  goto LBL_EXIT
)

echo.
echo Executing %LOCAL_FILE% on NCU %HOST% ...
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedKeyTypes=+ssh-rsa -oMacs=+hmac-sha1 -p %PORT% %USER%@%HOST% "bash %REMOTE_FILE%"
if NOT %errorlevel% == 0 (
  goto LBL_EXIT
)

:LBL_EXIT
echo.
pause
